<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
 * Moodle guest book block..
 *
 */

global $CFG;
require_once ($CFG->dirroot . '/blocks/guestb/lib/guestb_forms.php');

class generate_html {
	
	function __construct() {
		global $CFG;
		if (empty($CFG->msgtable)) {
			$this->tblmessages = 'block_guestb_messages';
		} else {
			$this->tblmessages = $CFG->msgtable;
		}
		if (empty($CFG->cmttable)) {
			$this->tblcomments = 'block_guestb_comments';
		} else {
			$this->tblcomments = $CFG->cmttable;
		}
	}
	
/**
 * Генерируем HTML-код для вывода сообщений
 * 
 * Подключается к базе данных, получает список сообщений в порядке от новых
 * к старым
 * @access public
 * @return string html-строка с формами сообщениий
 */	
	public function show_guestbook_messages() {
		global $DB;	
		$submitform = new moodlebook_submitform(null, array(
				'messageid' => 0,
				'commentid' => 0,
				'message' => 'Сообщение',
				'author' => 'Автор',
				'action' => 'submitbutton'
		));
	
		$msgid = "sdadsad";
		$cmtid = "dsff fs f";
		$message->text = "text";
		$message->author = "author";
		$action = "add";
		
		ob_start();
		$submitform = new moodlebook_submitform(null, array(
				'messageid' => $msgid,
				'commentid' => $cmtid,
				'message' => $message->text,
				'author' => $message->author,
				'action' => $action
		));
		$submitform->display();
		$html = ob_get_contents();
		ob_end_clean();
		
		
	//	$html = 'PRIVET show_guestbook_messages';
		return $html;
	}
	
	
}